Java | Objective-C |
---|---|
String | NSString |
BigDecimal (java.math) | NSDecimalNumber |
Number | NSNumber |
NSGregorianDate | NSCalendarDate |
NSData | NSData |
For example, in Oracle, VARCHAR columns are mapped to Strings, DATE columns are mapped to NSGregorianDates, and so on. The default mapping is appropriate for most data types, but you have to customize the mapping for attributes with special requirements.
For example, suppose you have a photo attribute that's stored in the database as a LONG RAW (an Oracle data type). When you create a new model, this attribute is mapped to an NSData. However, NSData is just an object-oriented wrapper for binary data-it doesn't have any methods for operating on images, which limits what you'd be able to do with the image in your application. So, for example, in an Application Kit application, you could customize the default behavior and map photo to an NSImage instead.
This section describes how to work with complex attributes such as RTF text, images, and custom data types. Of these attributes, RTF text is the easiest to handle. You don't have to change the default mapping at all, but you have to use special interface objects to display the RTF text.
For images and custom data types, you must customize the default mapping to map to a "non-primitive" class. To map to an existing class (such as NSImage for image attributes), you simply specify additional mapping information in EOModeler. You do the same work in EOModeler to use a custom class. However, you must also provide methods for translating instances of your class to instances of the primitive value classes.
Figure 21. Model Settings for an RTF Text Attribute
For Application Kit applications, Enterprise Objects Framework provides the EOTextAssociation class that extracts RTF text from an NSData object and displays it in an NSTextView object. To display an RTF text attribute in an Application Kit user interface, use Interface Builder to make a connection from a text object to your EODisplayGroup.
Note: Click in the text area to select the NSTextView before you control-drag to form the association. Unless the cursor is in the text area, control-dragging from the text area forms a connection from the text's super view, an NSScrollView. To be sure that the NSTextView is selected, open the inspector and check that it's displaying the NSTextView Inspector.
You probably wouldn't use RTF-formatted text in a WebObjects of Java client application. If you have RTF-formatted text that you want to use in a web application, the best approach is probably to filter the text to another format (such as plain text or HTML) before displaying it in a web page.
When you store image data in the database itself, Enterprise Objects Framework initially maps it to an NSData object. Depending on the type of application you're writing-WebObjects or Application Kit -you can leave the image as an NSData, or you can further map the NSData to an NSImage object.
Image data formats (EPS, BMP, and GIF, for example) are usually different for WebObjects and Application Kit applications. In a WebObjects application, you generally work with GIF and JPEG images; whereas Application Kit applications typically use EPS, TIFF, and BMP images.
There are numerous techniques for displaying images in a WebObjects application, so how you display them is up to you. (For more information, see the "Dynamic Elements Reference" in the WebObjects documentation set.) However, most of the approaches use binary image data, so it's customary to model image attributes as NSDatas when you're designing an enterprise object for use in a web application. If you store images in a binary column in the database, you can then simply use EOModeler's default mapping.
In an Application Kit application, model an enterprise object's image as an NSImage. In the EOModeler's Attribute Inspector:
Figure 22. Model Settings for an Image Attribute in an Application Kit Application
To display an image attribute in an Application Kit user interface, make an EOControlAssociation from an NSImageView object to your EODisplayGroup.
Enterprise Objects Framework maps attributes to a custom object using the same mechanism that it uses to map attributes to NSImages. In EOModeler's Attribute Inspector:
Binary data types such as Oracle's LONG RAW don't usually have width constraints. However, string columns such as VARCHARs often do have widths that you should enter.
This method should have one argument whose type matches the type specified in the Init Argument pop-up list.
This method should return an NSData object if the Init Argument type is NSData or Bytes, otherwise it should return an NSString.
Figure 23. Attribute Settings For a Custom Data Type
Using the mapping information in Figure 23, Enterprise Objects Framework fetches the phoneNumber attribute from the database, maps it to an NSString object, creates a PhoneNumber object using the PhoneNumber class method phoneNumberWithString:, and assigns the PhoneNumber object to its enterprise object. Similarly, Enterprise Objects Framework converts the PhoneNumber object to an NSString using the phoneNumberAsString method before saving it to the database.
For more information on using custom data types, see the EOAttribute class specification in the Enterprise Objects Framework Reference.
Table of Contents
Next Section